from django import newforms as forms
from PIL import Image
import os.path
import StringIO

def thumbnail(filename, size=(50, 50), output_filename=None):
	image = Image.open(filename)
	if image.mode not in ('L', 'RGB'):
		image = image.convert('RGB')
	image = image.resize(size, Image.ANTIALIAS)

# get the thumbnail data in memory.
	if not output_filename:
		output_filename = get_default_thumbnail_filename(output_filename)

	image.save(output_filename, image.format) 
	return output_filename

class FeedAddForm(forms.Form):
	url = forms.URLField()

class FeedPrefsForm(forms.Form):
	title = forms.CharField(max_length=200, required=False)
	username = forms.CharField(max_length=30, required=False)
	password = forms.CharField(max_length=30, required=False, widget=forms.PasswordInput)
	disabled = forms.BooleanField(required=False)
	color = forms.CharField(max_length=8, required=False)
	icon = forms.CharField(required=False, widget=forms.FileInput)

#	def clean_icon(self):
#		try:
#			thumbnail		

GENDER_CHOICES = (('M', 'Male'),
		('F', 'Female'),
		('O', 'Other'),
		('X', 'RatherNotSay'),
		)

class UserProfileForm(forms.Form):
	icon = forms.CharField(required=False, widget=forms.FileInput)
	first_name = forms.CharField(required=False)
	last_name = forms.CharField(required=False)  
	hidden = forms.BooleanField(required=False)
	gender = forms.ChoiceField(choices=GENDER_CHOICES)
	dob = forms.DateField(required=False)
	bio = forms.CharField(required=False, widget=forms.Textarea(attrs={'cols':40, 'rows':8}))
	website = forms.URLField(initial="http://", required=False)
	country = forms.CharField(required=False)
	province = forms.CharField(required=False)
	city = forms.CharField(required=False)
	postal_code = forms.CharField(required=False)

